package com.ym.base;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import lombok.Data;

import java.io.Serializable;
import java.sql.Timestamp;
import java.time.Instant;

@Data
public class BaseEntity implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 创建时间
     */
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    public Timestamp createTime;

    /**
     * 更新时间
     */
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    public Timestamp updateTime;

    //创建对象时初始化对象
    public void add() {
        this.setCreateTime(Timestamp.from(Instant.now()));
        this.setUpdateTime(Timestamp.from(Instant.now()));
    }
    //修改时间变更时用
    public void upd() {
        this.setUpdateTime(Timestamp.from(Instant.now()));
    }
}
